package leetcode100;

public class lc014 {
    public static void main(String[] args) {
        int[] prices = new int[]{7,6,4,3,1};
        int res = maxProfit(prices);/* 返回利润 */
        System.out.println("res = " + res);
    }

    public static int maxProfit(int[] prices) {
        int minPrice = Integer.MAX_VALUE;
        int maxDiff = 0;

        for (int price : prices) {
            if (price<minPrice) {
                minPrice = price;
            } else {
                maxDiff = Math.max(maxDiff,price-minPrice);
            }
        }
        return maxDiff;
    }
}
